package com.example.Rim.View;

import android.app.Activity;
import android.content.Intent;
import android.database.Cursor;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.*;
import com.example.Rim.R;

/**
 * Created by hulu on 2014/11/25.
 */
public class ActivitySecond extends Activity {

    private Button secondmainButton;
    private TextView secondTextView;
    private ListView secondListView;
    private boolean flag = true;
    private String list_text;
    private Button listButton;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.activity_second);

        secondmainButton = (Button) findViewById(R.id.secondmainButton);
        secondmainButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onBackPressed();
            }
        });
        secondTextView = (TextView) findViewById(R.id.secondTextView);

        Intent intent = getIntent();
        flag = intent.getBooleanExtra("flag",false);
        list_text = intent.getStringExtra("list_text");
        secondTextView.setText(list_text);

        secondListView = (ListView) findViewById(R.id.secondListView);
        secondListView.setAdapter(new SecondAdapter());

        secondListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

                TextView textView = (TextView) view.findViewById(R.id.listTextView);
                list_text =  textView.getText().toString();
                Intent intent = new Intent(ActivitySecond.this,ActivityMenu.class);
                intent.putExtra("list_text",list_text);
                startActivity(intent);
            }
        });
    }
    class SecondAdapter extends BaseAdapter{
        final String[] list={"餐饮服务","购物服务","生活服务","体育休闲服务","医疗保健服务","住宿服务","科教文化服务","交通设施服务"};
        @Override
        public int getCount() {
            return list.length;
        }

        @Override
        public Object getItem(int position) {
            return list[position];
        }

        @Override
        public long getItemId(int position) {
            return position;
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            View view = LayoutInflater.from(ActivitySecond.this).inflate(R.layout.list_menu,parent,false);
            final TextView list_textView = (TextView) view.findViewById(R.id.listTextView);
            list_textView.setText(list[position]);

            final String list_text =  list_textView.getText().toString();
            listButton = (Button) view.findViewById(R.id.listButton);
            if (flag){

            }else {
                listButton.setVisibility(View.GONE);
            }
            listButton.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    flag = false;
                    Intent intent = new Intent(ActivitySecond.this,ActivitySecond.class);
                    intent.putExtra("flag",flag);
                    intent.putExtra("list_text",list_text);
                    startActivity(intent);
                }
            });
            return view;
        }
    }
}
